package org.eclipse.football;

import static org.junit.Assert.fail;

import java.util.ArrayList;

import org.junit.Test;

public class SortPlayers {

	@Test
	public void test() {
		// Instantiate a team
		Team team = new Team("team","user");
	
		// Create 3 OffPlayers, 3 DefPlayers, and 3 kickers
		OffPlayer off_player1 = new OffPlayer("off_player1", "team");
		OffPlayer off_player2 = new OffPlayer("off_player2", "team");
		OffPlayer off_player3 = new OffPlayer("off_player3", "team");
		DefPlayer def_player1 = new DefPlayer("def_player1", "team");
		DefPlayer def_player2 = new DefPlayer("def_player2", "team");
		DefPlayer def_player3 = new DefPlayer("def_player3", "team");
		Kicker kicker1 = new Kicker("kicker1", "team");
		Kicker kicker2 = new Kicker("kicker2", "team");
		Kicker kicker3 = new Kicker("kicker3", "team");
		
		// Add stats to each offensive player
		off_player1.setPass_yds(100);
		off_player2.setPass_yds(200);
		off_player3.setPass_yds(300);
		off_player1.setPass_tds(3);
		off_player2.setPass_tds(2);
		off_player3.setPass_tds(0);
		off_player1.setPicks(2);
		off_player2.setPicks(1);
		off_player3.setPicks(0);
		off_player1.setRush_yds(100);
		off_player2.setRush_yds(10);
		off_player3.setRush_yds(0);
		off_player1.setRush_tds(2);
		off_player2.setRush_tds(3);
		off_player3.setRush_tds(10);
		off_player1.setRec_yds(100);
		off_player2.setRec_yds(10);
		off_player3.setRec_yds(2);
		off_player1.setRec_tds(0);
		off_player2.setRec_tds(1);
		off_player3.setRec_tds(2);
		off_player1.setFumbles(0);
		off_player2.setFumbles(10);
		off_player3.setFumbles(100);
		off_player1.setRet_tds(1);
		off_player2.setRet_tds(3);
		off_player3.setRet_tds(10);
		
		// Add stats to defensive players
		def_player1.setDef_tds(0);
		def_player2.setDef_tds(1);
		def_player3.setDef_tds(2);
		def_player1.setPicks(2);
		def_player2.setPicks(1);
		def_player3.setPicks(0);
		def_player1.setFumbles(0);
		def_player2.setFumbles(1);
		def_player3.setFumbles(2);
		def_player1.setSacks(4);
		def_player2.setSacks(3);
		def_player3.setSacks(1);
		def_player1.setBlocks(1);
		def_player2.setBlocks(2);
		def_player3.setBlocks(10);
		def_player1.setSafeties(110);
		def_player2.setSafeties(11);
		def_player3.setSafeties(2);
		def_player1.setPa(1011);
		def_player2.setPa(201);
		def_player3.setPa(30);
		def_player1.setYa(4);
		def_player2.setYa(10);
		def_player3.setYa(20);
		
		// Add stats to kickers
		kicker1.setPat(1);
		kicker2.setPat(2);
		kicker3.setPat(0);
		kicker1.setFg(0);
		kicker2.setFg(1);
		kicker3.setFg(2);
		kicker1.setMisses(1);
		kicker2.setMisses(2);
		kicker3.setMisses(0);
		
		// Add players to team
		team.addOffPlayer(off_player1);
		team.addDefPlayer(def_player1);
		team.addKicker(kicker1);
		team.addOffPlayer(off_player2);
		team.addDefPlayer(def_player2);
		team.addKicker(kicker2);
		team.addOffPlayer(off_player3);
		team.addDefPlayer(def_player3);
		team.addKicker(kicker3);
		
		// Sort players by pass_yds
		team.sortOffPlayers(0);
		
		// Get this teams OffPlayers array
		ArrayList<OffPlayer> off_players = team.getOff_players();
		
		// Iterate from first off_player in team to second to last off_player in team
		for(int i = 0; i < off_players.size() - 1; i++){
			// Make sure this players's pass_yds are not less than the next players
			if(off_players.get(i).getPass_yds() < off_players.get(i+1).getPass_yds()){
				// If not then fail
				fail("Players's were not sorted correctly by passing yards\n");
			}
		}
		
		// Sort players by pass_tds
		team.sortOffPlayers(1);
		
		// Get this teams OffPlayers array
		off_players = team.getOff_players();
		
		// Iterate from first off_player in team to second to last off_player in team
		for(int i = 0; i < off_players.size() - 1; i++){
			// Make sure this players's pass_tds are not less than the next players
			if(off_players.get(i).getPass_tds() < off_players.get(i+1).getPass_tds()){
				// If not then fail
				fail("Players's were not sorted correctly by passing touchdowns\n");
			}
		}
		
		// Sort players by picks
		team.sortOffPlayers(2);
		
		// Get this teams OffPlayers array
		off_players = team.getOff_players();
		
		// Iterate from first off_player in team to second to last off_player in team
		for(int i = 0; i < off_players.size() - 1; i++){
			// Make sure this players's picks are not more than the next players
			if(off_players.get(i).getPicks() > off_players.get(i+1).getPicks()){
				// If not then fail
				fail("Players's were not sorted correctly by picks\n");
			}
		}
		
		// Sort players by rush_yds
		team.sortOffPlayers(3);
		
		// Get this teams OffPlayers array
		off_players = team.getOff_players();
		
		// Iterate from first off_player in team to second to last off_player in team
		for(int i = 0; i < off_players.size() - 1; i++){
			// Make sure this players's rush_yds are not less than the next players
			if(off_players.get(i).getRush_yds() < off_players.get(i+1).getRush_yds()){
				// If not then fail
				fail("Players's were not sorted correctly by rushing yards\n");
			}
		}
		
		// Sort players by rush_tds
		team.sortOffPlayers(4);
		
		// Get this teams OffPlayers array
		off_players = team.getOff_players();
		
		// Iterate from first off_player in team to second to last off_player in team
		for(int i = 0; i < off_players.size() - 1; i++){
			// Make sure this players's rush_tds are not less than the next players
			if(off_players.get(i).getRush_tds() < off_players.get(i+1).getRush_tds()){
				// If not then fail
				fail("Players's were not sorted correctly by rushing touchdowns\n");
			}
		}
		
		// Sort players by rec_yds
		team.sortOffPlayers(5);
		
		// Get this teams OffPlayers array
		off_players = team.getOff_players();
		
		// Iterate from first off_player in team to second to last off_player in team
		for(int i = 0; i < off_players.size() - 1; i++){
			// Make sure this players's rec_yds are not less than the next players
			if(off_players.get(i).getRec_yds() < off_players.get(i+1).getRec_yds()){
				// If not then fail
				fail("Players's were not sorted correctly by receiving  yards\n");
			}
		}
		
		// Sort players by rec_tds
		team.sortOffPlayers(6);
		
		// Get this teams OffPlayers array
		off_players = team.getOff_players();
		
		// Iterate from first off_player in team to second to last off_player in team
		for(int i = 0; i < off_players.size() - 1; i++){
			// Make sure this players's rec_tds are not less than the next players
			if(off_players.get(i).getRec_tds() < off_players.get(i+1).getRec_tds()){
				// If not then fail
				fail("Players's were not sorted correctly by receiving touchdowns\n");
			}
		}
		
		// Sort players by fumbles
		team.sortOffPlayers(7);
		
		// Get this teams OffPlayers array
		off_players = team.getOff_players();
		
		// Iterate from first off_player in team to second to last off_player in team
		for(int i = 0; i < off_players.size() - 1; i++){
			// Make sure this players's fumbles are not more than the next players
			if(off_players.get(i).getFumbles() > off_players.get(i+1).getFumbles()){
				// If not then fail
				fail("Players's were not sorted correctly by fumbles\n");
			}
		}
		
		// Sort players by ret_tds
		team.sortOffPlayers(8);
		
		// Get this teams OffPlayers array
		off_players = team.getOff_players();
		
		// Iterate from first off_player in team to second to last off_player in team
		for(int i = 0; i < off_players.size() - 1; i++){
			// Make sure this players's ret_tds are not less than the next players
			if(off_players.get(i).getRet_tds() < off_players.get(i+1).getRet_tds()){
				// If not then fail
				fail("Players's were not sorted correctly by returnd touchdowns\n");
			}
		}
		
		// Sort players by points
		team.sortOffPlayers(9);
				
		// Get this teams OffPlayers array
		off_players = team.getOff_players();
				
		// Iterate from first off_player in team to second to last off_player in team
		for(int i = 0; i < off_players.size() - 1; i++){
			// Make sure this players's points are not less than the next players
			if(off_players.get(i).calculatePoints() < off_players.get(i+1).calculatePoints()){					// If not then fail
				fail("Players's were not sorted correctly by points\n");
			}
		}
				
		// Sort def_players by tds
		team.sortDefPlayers(0);
				
		// Get this teams def_players array
		ArrayList<DefPlayer> def_players = team.getDef_players();
				
		// Iterate from first def_player in team to second to last def_player in team
		for(int i = 0; i < def_players.size() - 1; i++){
			// Make sure this def_players tds are not less than the next def_players
			if(def_players.get(i).getDef_tds() < def_players.get(i+1).getDef_tds()){
				// If not then fail
				fail("Defensive players were not sorted correctly by touchdowns\n");
			}
		}
		
		// Sort def_players by picks
		team.sortDefPlayers(1);
				
		// Get this teams def_players array
		def_players = team.getDef_players();
				
		// Iterate from first def_player in team to second to last def_player in team
		for(int i = 0; i < def_players.size() - 1; i++){
			// Make sure this def_players picks are not less than the next def_players
			if(def_players.get(i).getPicks() < def_players.get(i+1).getPicks()){
				// If not then fail
				fail("Defensive players were not sorted correctly by picks\n");
			}
		}
		
		// Sort def_players by fumbles
		team.sortDefPlayers(2);
				
		// Get this teams def_players array
		def_players = team.getDef_players();
				
		// Iterate from first def_player in team to second to last def_player in team
		for(int i = 0; i < def_players.size() - 1; i++){
			// Make sure this def_players fumbles are not less than the next def_players
			if(def_players.get(i).getFumbles() < def_players.get(i+1).getFumbles()){
				// If not then fail
				fail("Defensive players were not sorted correctly by fumbles\n");
			}
		}
		
		// Sort def_players by sacks
		team.sortDefPlayers(3);
				
		// Get this teams def_players array
		def_players = team.getDef_players();
				
		// Iterate from first def_player in team to second to last def_player in team
		for(int i = 0; i < def_players.size() - 1; i++){
			// Make sure this def_players sacks are not less than the next def_players
			if(def_players.get(i).getSacks() < def_players.get(i+1).getSacks()){
				// If not then fail
				fail("Defensive players were not sorted correctly by sacks\n");
			}
		}
		
		// Sort def_players by picks
		team.sortDefPlayers(4);
				
		// Get this teams def_players array
		def_players = team.getDef_players();
				
		// Iterate from first def_player in team to second to last def_player in team
		for(int i = 0; i < def_players.size() - 1; i++){
			// Make sure this def_players blocks are not less than the next def_players
			if(def_players.get(i).getBlocks() < def_players.get(i+1).getBlocks()){
				// If not then fail
				fail("Defensive players were not sorted correctly by blocks\n");
			}
		}
		
		// Sort def_players by safeties
		team.sortDefPlayers(5);
				
		// Get this teams def_players array
		def_players = team.getDef_players();
				
		// Iterate from first def_player in team to second to last def_player in team
		for(int i = 0; i < def_players.size() - 1; i++){
			// Make sure this def_players safeties are not less than the next def_players
			if(def_players.get(i).getSafeties() < def_players.get(i+1).getSafeties()){
				// If not then fail
				fail("Defensive players were not sorted correctly by safeties\n");
			}
		}
		
		// Sort def_players by pa
		team.sortDefPlayers(6);
				
		// Get this teams def_players array
		def_players = team.getDef_players();
				
		// Iterate from first def_player in team to second to last def_player in team
		for(int i = 0; i < def_players.size() - 1; i++){
			// Make sure this def_players pa are not more than the next def_players
			if(def_players.get(i).getPa() > def_players.get(i+1).getPa()){
				// If not then fail
				fail("Defensive players were not sorted correctly by points allowed\n");
			}
		}
		
		// Sort def_players by ya
		team.sortDefPlayers(7);
				
		// Get this teams def_players array
		def_players = team.getDef_players();
				
		// Iterate from first def_player in team to second to last def_player in team
		for(int i = 0; i < def_players.size() - 1; i++){
			// Make sure this def_players ya are not more than the next def_players
			if(def_players.get(i).getYa() > def_players.get(i+1).getYa()){
				// If not then fail
				fail("Defensive players were not sorted correctly by yards allowed\n");
			}
		}
		
		// Sort def_players by points
		team.sortDefPlayers(8);
				
		// Get this teams def_players array
		def_players = team.getDef_players();
				
		// Iterate from first def_player in team to second to last def_player in team
		for(int i = 0; i < def_players.size() - 1; i++){
			// Make sure this def_players points are not less than the next def_players
			if(def_players.get(i).calculatePoints() < def_players.get(i+1).calculatePoints()){
				// If not then fail
				fail("Defensive players were not sorted correctly by points\n");
			}
		}
		
		// Sort kickers by pat
		team.sortKickers(0);
				
		// Get this teams kickers array
		ArrayList<Kicker> kickers = team.getKickers();
				
		// Iterate from first kicker on team to second to last kicker on team
		for(int i = 0; i < kickers.size() - 1; i++){
			// Make sure this kickers pat are not less than the next kickers
			if(kickers.get(i).getPat() < kickers.get(i+1).getPat()){
				// If not then fail
				fail("Kickers were not sorted correctly by PAT\n");
			}
		}
		
		// Sort kickers by fg
		team.sortKickers(1);
				
		// Get this teams kickers array
		kickers = team.getKickers();
				
		// Iterate from first kicker on team to second to last kicker on team
		for(int i = 0; i < kickers.size() - 1; i++){
			// Make sure this kickers fg0 are not less than the next kickers
			if(kickers.get(i).getFg() < kickers.get(i+1).getFg()){
				// If not then fail
				fail("Kickers were not sorted correctly by short field goals\n");
			}
		}
		
		// Sort kickers by misses
		team.sortKickers(2);
				
		// Get this teams kickers array
		kickers = team.getKickers();
				
		// Iterate from first kicker on team to second to last kicker on team
		for(int i = 0; i < kickers.size() - 1; i++){
			// Make sure this kickers misses are not more than the next kickers
			if(kickers.get(i).getMisses() > kickers.get(i+1).getMisses()){
				// If not then fail
				fail("Kickers were not sorted correctly by misses\n");
			}
		}
		
		// Sort kickers by points
		team.sortKickers(3);
				
		// Get this teams kickers array
		kickers = team.getKickers();
				
		// Iterate from first kicker on team to second to last kicker on team
		for(int i = 0; i < kickers.size() - 1; i++){
			// Make sure this kickers points are not less than the next kickers
			if(kickers.get(i).calculatePoints() < kickers.get(i+1).calculatePoints()){
				// If not then fail
				fail("Kickers were not sorted correctly by points\n");
			}
		}
	}
}
